package wyh.controller.Escort;

import com.fasterxml.jackson.databind.ObjectMapper;
import wyh.pojo.Escort;
import wyh.service.EscortService;
import wyh.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/Escort/add")
public class AddServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ObjectMapper ojmapper = new ObjectMapper();
        Escort pojo = ojmapper.readValue(req.getInputStream(), Escort.class);
        System.out.println(pojo);
        EscortService service = new EscortService();
        Boolean a = service.Serviceadd(pojo);
        Result result = null;
        if (a) {
            result = new Result(200, "成功添加", null);
        } else {
            result = new Result(500, "添加失败", null);
        }
        String string = ojmapper.writeValueAsString(result);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(string);
    }
}
